package com.example.origin.demo.demo.currentprint;

import java.util.concurrent.CountDownLatch;

public class AlteratePrint4 {
    static Thread threadA = null;
    static Thread threadB = null;


    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(100);
        threadA = new Thread(() -> {
            while (countDownLatch.getCount()>0) {
                if (countDownLatch.getCount()%2==0) {
                    System.out.print(countDownLatch.getCount()+" ");
                    countDownLatch.countDown();
                }
            }
        });
        threadB = new Thread(() -> {
            while (countDownLatch.getCount()>0) {
                if (countDownLatch.getCount()%2==1) {
                    System.out.print(countDownLatch.getCount()+" ");
                    countDownLatch.countDown();
                }
            }
        });

        threadA.start();
        threadB.start();

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }


    }
}